//
//  NormalGoalSetupItemView.swift
//  DaRings
//
//  Created by 魔样科技 on 2022/11/12.
//

import Foundation
import MYModule

class GoalSetupNormalItemView: View {
    
    override func makeUI() {
        super.makeUI()
        
        self.addSubview(self.titleLabel)
        self.titleLabel.snp.makeConstraints { make in
            make.leading.equalTo(20)
            make.centerY.equalToSuperview()
        }
        
        self.addSubview(self.pickerAndUnitView)
        self.pickerAndUnitView.snp.makeConstraints { make in
            make.trailing.equalTo(-20)
            make.centerY.equalToSuperview()
            make.top.equalTo(25)
        }
        
        self.addSubview(self.underscoreView)
        self.underscoreView.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.leading.equalTo(20)
            make.centerX.equalToSuperview()
            make.height.equalTo(0.5)
        }
        
    }
    
    public func bindModel(model: GoalSetupNormalItemModel) {
        
        self.titleLabel.text = model.title
        self.pickerAndUnitView.unitLabel.text = model.pickerModel.unit
        self.pickerAndUnitView.pickerView.titles = model.pickerModel.pickerDataArray
        self.pickerAndUnitView.pickerView.didSelectItem(atIndex: model.pickerModel.selectIndex)
        self.pickerAndUnitView.updatePickerFrame(_withWidth: model.pickerModel.pickerWidth)
        self.pickerAndUnitView.pickerView.returnDidSelectClosure { value in
            model.pickerModel.selectIndex = value
        }
    }
    
    //MARK: - lazy load -
    public lazy var titleLabel: Label = {
        let label = Label()
        label.textColor = UIColor.assist_222222
        label.font = Fonts.systemFont(ofSize: 16)
        return label
    }()
    
    public lazy var pickerAndUnitView: GoalSetupPickerAndUnitView = {
        let pickerView = GoalSetupPickerAndUnitView()
        return pickerView
    }()
    
    public lazy var underscoreView: View = {
        let view = View()
        view.backgroundColor = .assist_D0D0D0
        return view
    }()
}
